import { Component, OnInit, ViewChild } from '@angular/core';
import { STChange, STColumn, STComponent } from '@delon/abc/st';
import { SFComponent, SFSchema, SFDateWidgetSchema } from '@delon/form';
import { NzModalService } from 'ng-zorro-antd/modal';
import { SystemService } from '../../services/system.service';
import { AuditResonConfigActionModalComponent } from './audit-reson-config-action-modal/audit-reson-config-action-modal.component';

@Component({
  selector: 'app-audit-reason-config',
  templateUrl: './audit-reason-config.component.html',
  styleUrls: ['./audit-reason-config.component.less']
})
export class AuditReasonConfigComponent implements OnInit {
  @ViewChild('st', { static: true })
  st!: STComponent;
  @ViewChild('sf', { static: false })
  sf!: SFComponent;

  url = `/rule?_allow_anonymous=true`;

  searchSchema: SFSchema = {
    properties: {
      expand: {
        type: 'boolean',
        ui: {
          hidden: true
        }
      },
      receiveName: {
        type: 'string',
        title: '审核类型',
        enum: [
          { label: '全部', value: '全部' },
          { label: '企业认证审核', value: '企业认证审核' },
          { label: '企业管理员审核', value: '企业管理员审核' },
          { label: '用户实名认证审核', value: '用户实名认证审核' },
          { label: '司机实名认证审核', value: '司机实名认证审核' },
          { label: '司机驾驶证审核', value: '司机驾驶证审核' },
          { label: '车辆审核', value: '车辆审核' }
        ],
        ui: {
          widget: 'select',
          placeholder: '请选择',
          change: (i: any) => {
            this.sf.value.receiveName = i;
            this.sf?.setValue('/receiveName', i);
          }
        }
      },
      phone: {
        type: 'string',
        title: '驳回理由',
        ui: { placeholder: '请输入' }
      },
      createTime: {
        title: '创建时间',
        type: 'string',
        ui: {
          widget: 'date',
          mode: 'range',
          format: 'yyyy-MM-dd'
        } as SFDateWidgetSchema
      }
    }
  };

  columns: STColumn[] = [
    { title: '操作时间', index: 'updatedAt', type: 'date' },
    { title: '操作人', index: 'description' },
    { title: '操作人手机号码', index: 'description' },
    { title: '操作页面', index: 'description' },
    { title: '操作内容', index: 'description' },
    {
      title: '创建时间',
      index: 'updatedAt',
      type: 'date'
    },
    {
      title: '操作',
      className: 'text-center',
      buttons: [
        {
          text: '编辑',
          click: item => this.reasonAction(item)
        },
        {
          text: '删除',
          click: item => this.deleteReason(item)
        }
      ]
    }
  ];

  reqParams = { pageIndex: 1, pageSize: 10 };

  constructor(public service: SystemService, private nzModalService: NzModalService) {}

  ngOnInit(): void {}

  stChange(e: STChange): void {}

  reasonAction(item?: any) {
    const modal = this.nzModalService.create({
      nzContent: AuditResonConfigActionModalComponent,
      nzComponentParams: item ? { i: { ...item, roleId: 1, name: '车辆审核', phone: 18555555555 } } : { i: { id: 0 } },
      nzFooter: null
    });
    modal.afterClose.subscribe(res => {
      this.st.load();
    });
  }

  deleteReason(item: any) {
    this.nzModalService.error({
      nzTitle: '确认删除？',
      nzClosable: false,
      nzCancelText: '取消',
      nzOnOk: () => {}
    });
  }

  /**
   * 重置表单
   */
  resetSF() {
    this.sf.reset();
  }
}
